//
//  PPWateFallDetailView.m
//  pet
//
//  Created by 陈无忌 on 12/12/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPWateFallDetailView.h"

@implementation PPWateFallDetailView


- (id)init
{
    self = [super init];
    if (self) {
        //默认未选择
        self.isSelect = NO;
        self.selectTag = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH -30, SPACE, 30, 30)];
        [self.selectTag setImage:[UIImage imageNamed:@"selectPetPhoto"]];
        self.selectTag.hidden = YES;
        // Initialization code
    }
    return self;
}

- (UIView *)drawViewWithImg:(petPhotoModel *)model AndY:(CGFloat)y
{
    self.model = model;
    
    CGFloat imgW = model.image.size.width;
    CGFloat imgH = model.image.size.height;
    
    UIImageView *imageview = [[UIImageView alloc] initWithImage:model.image];
    
    imageview.frame = CGRectMake(SPACE, SPACE, WIDTH - SPACE, imgH * (WIDTH - SPACE) /imgW );
    [self addSubview:imageview];
    [self addSubview:self.selectTag];
    self.frame = CGRectMake(0, y, WIDTH, imgH * (WIDTH - SPACE) /imgW + SPACE);
    return self;
}

//触摸
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.delegate clickImage:self.model];
    if (self.isSelect) {
        self.isSelect = NO;
        self.selectTag.hidden = YES;
        
    }else{
        self.isSelect = YES;
        self.selectTag.hidden = NO;
    }
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
